package com.zy.ivideo.service;

import com.zy.ivideo.entity.ResponseEntity;
import com.zy.ivideo.entity.VideoAuthorEntity;
import com.zy.ivideo.repository.VideoAuthorRepository;
import com.zy.ivideo.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Repository
public class VideoAuthorService {
    @Autowired
    VideoAuthorRepository repository;

    @Autowired
    EntityManager entityManager;

    /**
     * 通过userid获取对应作者信息
     * @param userid
     * @return
     */
    public ResponseEntity<VideoAuthorEntity> getAuthorById(String userid){
        String sql="select * from b_video_author";
        Query query = entityManager.createNativeQuery(sql, VideoAuthorEntity.class);
        List<VideoAuthorEntity> resultList = query.getResultList();
        if (resultList==null||resultList.size()==0){
            return ResponseUtils.failed("没有检索到该作者信息");
        }
        return ResponseUtils.success(resultList.get(0));

    }
}
